<script type="text/javascript">
	
	function batal(){
		document.location.href = '<?=base_url().'index.php/pembelian'?>';
	}
	
	$(function(){
		$("#tanggal").datepicker({dateFormat: 'yy-mm-dd', yearRange: '2001:2021' });
	})
	
	function save_data(){
		
		var isi = document.getElementById('detail').innerHTML;

		if( isi == false){
			document.getElementById('alert_yanto').innerHTML = '<ul class="message error grid_12"><li>List data barang tidak boleh kosong</li><li class="close-bt"></li></ul><br>';
			//alert('kosong');
			$('html, body').stop().animate({
				scrollTop: 0 //$($anchor.attr('href')).offset().top
			}, 700, 'easeInOutExpo');
		}else{
			document.getElementById('alert_yanto').innerHTML = '';
			//alert('berisi');
			document.forms["form1"].submit();
		}
		
	}
	
</script>

<script type="text/javascript">
	
	
	$(document).ready(function() {
		$("#getbarang").fancybox();
	});
	
	
	function set_detail(){
		
		if(document.getElementById('detail_namabarang').value == ''){
			alert('Isi nama barang terlebih dahulu.');
		}else{
			$.ajax({
				type: 'POST',
				url: '<?=base_url().'asset/admin/js/ajax_pembelian.php?command=add_1'?>',
				data: $('#form1').serialize(),
				success: function(data) {
					$('#detail').html(data);
				}
			});
			
			document.getElementById('detail_idbarang').value = '';	
			document.getElementById('detail_namabarang').value = '';
			document.getElementById('detail_harga').value = '';
			document.getElementById('detail_harga_toko').value = '';
			document.getElementById('detail_harga_partai').value = '';
			document.getElementById('detail_harga_cabang').value = '';
			document.getElementById('detail_qty').value = '';
			document.getElementById('detail_jatuh_tempo').value = '';
		}
	}
	
	function remove_detail(id){
		$.ajax({
			type: 'POST',
			url: '<?=base_url().'asset/admin/js/ajax_pembelian.php?command=remove&id='?>'+id,
			data: $('#form1').serialize(),
			success: function(data) {
				$('#detail').html(data);
			}
		});
		
	}

		function klick_tanggal(){
		var tanggal = document.getElementById("tanggal");
		tanggal.focus();
	}	

</script>

	<?php 
		if(validation_errors())
		{
	?>
			<ul class="message error grid_12">
				<li><?=validation_errors()?></li>
				<li class="close-bt"></li>
			</ul>	
	<?php
		} 
	?>
	
<div id="alert_yanto"></div><br>

<section class="grid_12">
	<div class="block-border">
		<?php
			$attributes = array('name' => 'form1', 'id' => 'form1', 'class'=>'block-content form');
			echo form_open('refund/process_koreksi', $attributes);
		?>
			<h1>Kas Dan Bank > Refund</h1>
			<fieldset class="grey-bg margin">
				<div class="columns">
					<!--<input type="hidden" name="glid" id="glid" value="<?//=$result->row()->GLID?>">-->
					<p class="colx3-left">
						<label for="complex-en-url">Glid :</label>
						<span class="relative">
							<input type="text" name="glid" readonly="true" id="glid" value="<?=$result->row()->GLID?>">							<input type="hidden" name="KOUNIT" readonly="true" id="KOUNIT" value="<?=$results->row()->KOUNIT?>">							<input type="hidden" name="PARTNERID" readonly="true" id="PARTNERID" value="<?=$results->row()->PARTNERID?>">
						</span>
					</p>										<p class="colx3-center">						<label for="complex-en-url">Pilihan :</label>						<span class="relative">						<?php 							if ($results->row()->PO_ID == 'PO'){									echo '<input type="radio" name="id_pilihan" value="kredit" checked="checked" /> Penambahan';									echo '<input type="radio" name="id_pilihan" value="debet" /> Debet<br/>';							}else if ($results->row()->PO_ID == 'SO'){								echo '<input type="radio" name="id_pilihan" value="kredit" /> Kredit';								echo '<input type="radio" name="id_pilihan" value="debet" checked="checked" /> Pengurangan<br/>';							}else{								echo '<input type="radio" name="id_pilihan" value="kredit" /> Kredit';								echo '<input type="radio" name="id_pilihan" value="debet" /> Debet<br/>';							}						?>																				</span>					</p>					
					<p class="colx3-right">
						<label for="complex-en-url">Tanggal :</label>
						<span class="relative">
							<span class="input-type-text margin-right relative">
								<input type="text" name="tanggal" id="tanggal" class="datepicker" value="<?=$result->row()->CDATE?>">
								<img onclick="javascript:klick_tanggal()" src="<?=base_url()?>asset/admin/images/icons/fugue/calendar-month.png" width="16" height="16">
							</span>
						</span>
					</p>
				</div>
				<div class="columns">					<p class="colx3-left">						<label for="complex-en-url">Akunid :</label>						<span class="relative">							<?php								$j=0;								foreach ($result->result() as $rows){									$query = $this->db->query("SELECT distinct(AKUNID),NAKUN  FROM `master_akun` WHERE `AKUNID`='" . $rows->AKUNID . "'");									if($query->num_rows() > 0)									{										if ($results->row()->PO_ID == 'PO'){											foreach($query->result() as $row_nakun)											{												if ($rows->KREDIT == 0){													echo "<input type='text' readonly='true' name='refund[$j][nakun]' value='$row_nakun->NAKUN' />";													echo "<input type='text' readonly='true' name='refund[$j][akunid]' value='$rows->AKUNID' /><br/><br/>";												}else{													echo "<input type='text' readonly='true' name='refund[$j][nakun]' value='$row_nakun->NAKUN' />";													echo "<input type='text' readonly='true' name='refund[$j][akunid]' value='$rows->AKUNID' /><br/>";												}											}											}else if ($results->row()->PO_ID == 'SO'){												foreach($query->result() as $row_nakun)												{													if ($rows->KREDIT == 0){														echo "<input type='text' readonly='true' name='refund[$j][nakun]' value='$row_nakun->NAKUN' />";														echo "<input type='text' readonly='true' name='refund[$j][akunid]' value='$rows->AKUNID' /><br/>";													}else{														echo "<input type='text' readonly='true' name='refund[$j][nakun]' value='$row_nakun->NAKUN' />";														echo "<input type='text' readonly='true' name='refund[$j][akunid]' value='$rows->AKUNID' /><br/><br/>";													}												}										}else{											foreach($query->result() as $row_nakun)												{													if ($rows->KREDIT == 0){														echo "<input type='text' readonly='true' name='refund[$j][nakun]' value='$row_nakun->NAKUN' />";														echo "<input type='text' readonly='true' name='refund[$j][akunid]' value='$rows->AKUNID' /><br/>";													}else{														echo "<input type='text' readonly='true' name='refund[$j][nakun]' value='$row_nakun->NAKUN' />";														echo "<input type='text' readonly='true' name='refund[$j][akunid]' value='$rows->AKUNID' /><br/><br/>";													}												}										}									}																									$j++;								}							?>					</span>					</p>				
					<p class="colx3-center">						<label for="complex-en-url">Nominal :</label>						<span class="relative">							<?php								$i=0;								if ($results->row()->PO_ID == 'PO'){									foreach ($result->result() as $rows){																				if ($rows->KREDIT == 0){											echo "<input type='text' name='refund[$i][nominal_read_d_user]' readonly='true' value='" . convert_rupiah_non_rp($rows->DEBET) . "' />";											echo "<input type='hidden' name='refund[$i][nominal_read_d]' readonly='true' value='$rows->DEBET' /><br/><br/>";																					}else{																					echo "<input type='text' name='refund[$i][nominal_read_k_user]' readonly='true' value='" . convert_rupiah_non_rp($rows->KREDIT) . "' align='right' />";											echo "<input type='hidden' name='refund[$i][nominal_read_k]' readonly='true' value='$rows->KREDIT' align='right' /><br/>";										}										$i++;										}								}else if ($results->row()->PO_ID == 'SO'){									foreach ($result->result() as $rows){																				if ($rows->KREDIT == 0){											echo "<input type='text' name='refund[$i][nominal_read_d_user]' readonly='true' value='" . convert_rupiah_non_rp($rows->DEBET) . "' />";											echo "<input type='hidden' name='refund[$i][nominal_read_d]' readonly='true' value='$rows->DEBET' /><br/>";																					}else{																					echo "<input type='text' name='refund[$i][nominal_read_k_user]' readonly='true' value='" . convert_rupiah_non_rp($rows->KREDIT) . "' align='right' />";											echo "<input type='hidden' name='refund[$i][nominal_read_k]' readonly='true' value='$rows->KREDIT' align='right' /><br/><br/>";										}										$i++;										}								}else{										foreach ($result->result() as $rows){																				if ($rows->KREDIT == 0){											echo "<input type='text' name='refund[$i][nominal_read_d_user]' readonly='true' value='" . convert_rupiah_non_rp($rows->DEBET) . "' />";											echo "<input type='hidden' name='refund[$i][nominal_read_d]' readonly='true' value='$rows->DEBET' /><br/>";																					}else{																					echo "<input type='text' name='refund[$i][nominal_read_k_user]' readonly='true' value='" . convert_rupiah_non_rp($rows->KREDIT) . "' align='right' />";											echo "<input type='hidden' name='refund[$i][nominal_read_k]' readonly='true' value='$rows->KREDIT' align='right' /><br/><br/>";										}										$i++;										}								}							?>						</span>					</p>															<p class="colx3-right">						<label for="complex-en-url">Nominal Isian :</label>						<span class="relative">							<?php								$i=0;								if ($results->row()->PO_ID == 'PO'){									foreach ($result->result() as $rows){																			if ($rows->KREDIT == 0){											echo "<input type='text' name='refund[$i][nominal_d]' value='' /><br/><br/>";										}else{											echo "<input type='text' name='refund[$i][nominal_k]' value='' /><br/>";										}										$i++;										}								}else if ($results->row()->PO_ID == 'SO'){									foreach ($result->result() as $rows){																			if ($rows->KREDIT == 0){											echo "<input type='text' name='refund[$i][nominal_d]' value='' /><br/>";										}else{											echo "<input type='text' name='refund[$i][nominal_k]' value='' /><br/><br/>";										}										$i++;										}								}else{									foreach ($result->result() as $rows){																			if ($rows->KREDIT == 0){											echo "<input type='text' name='refund[$i][nominal_d]' value='' /><br/>";										}else{											echo "<input type='text' name='refund[$i][nominal_k]' value='' /><br/><br/>";										}										$i++;										}								}							?>						</span>					</p>					
				</div>					<div class="columns">					<p class="colx3-left">						<label for="complex-en-url">Keterangan :</label>						<span class="relative">							<textarea name="keterangan"  cols="35" rows="5" value=""></textarea>						</span>											</p>					</div>
			</fieldset>
			
						
			<div id="tab-settings" class="tabs-content">
					<button type="submit"><img src="<?=base_url()?>asset/admin/images/icons/fugue/tick-circle.png" width="16" height="16"> Simpan</button>
					<button type="button" onclick="javascript:batal();" class="red">Batal</button> 		
			</div>	
		</form>
	</div>
	
</section>



